package org.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.example.entity.ThirdDeduct;
import org.example.service.IThirdDeductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 第三方划扣表 前端控制器
 * </p>
 *
 * @author libo
 * @since 2023-11-15
 */
@RestController
@RequestMapping("/third-deduct")
public class ThirdDeductController {

    @Autowired
    private IThirdDeductService thirdDeductService;

    @GetMapping("get")
    public List<ThirdDeduct> find() throws ParseException {
        QueryWrapper<ThirdDeduct> wrapper = new QueryWrapper<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        wrapper.between("create_time", sdf.parse("2023-10-15"), sdf.parse("2023-11-20"));
        return thirdDeductService.list(wrapper);
    }

    @GetMapping("save")
    public ThirdDeduct save() {
        ThirdDeduct thirdDeduct = ThirdDeduct.builder().build();
        thirdDeductService.save(thirdDeduct);
        return thirdDeduct;
    }

    @GetMapping("update")
    public ThirdDeduct update(@RequestParam()Long id) {
        ThirdDeduct thirdDeduct = thirdDeductService.getById(id);
        UpdateWrapper<ThirdDeduct> thirdDeductUpdateWrapper = new UpdateWrapper<>();
        thirdDeductUpdateWrapper.eq("id",id);
        thirdDeductUpdateWrapper.eq("create_time",thirdDeduct.getCreateTime());
        thirdDeductService.update(thirdDeduct,thirdDeductUpdateWrapper);

        return thirdDeduct;
    }
}

